//
//  NetworkTool+OAuth.swift
//  新浪微博练习
//
//  Created by 韩旭 on 16/11/27.
//  Copyright © 2016年 韩旭. All rights reserved.
//

import Foundation

extension NetworkTool {

    func requestAccessToken(code: String, callBack:@escaping(_
        responseObject:Any?)->()) {
        let urlString = "https://api.weibo.com/oauth2/access_token"
        let  parameters = [
            "client_id" : appkey,
            "client_secret": appSecret,
            "grant_type": "authorization_code",
            "code":code,
            "redirect_uri": reditrectURI,
            ]

        request(url: urlString, parameters: parameters, method: "POST", callBack:{
            (responseObject) in
            callBack(responseObject)
            
        })
    }
    
    
    func requestUserAccount(access_token: String, uid: String, callBack: @escaping (_ responseObject: Any?)->()) {
     //使用code获取access_token
        let urlStr = "https://api.weibo.com/2/users/show.json"
        
        let parameters = ["access_token": access_token,
                          "uid": uid]
        request(url: urlStr, parameters: parameters, method: "GET", callBack:{
            (responseObject) in
            callBack(responseObject)
        })
    }
}
